<?php
namespace common\helpers;

use yii\helpers\BaseJson;

class Test extends BaseJson
{
    public static function ajaxReturn($data,$type='json',$json_option=0)
    {
        switch (strtoupper($type)){
            case 'JSON' :
                // 返回JSON数据格式到客户端 包含状态信息
                header('Content-Type:application/json; charset=utf-8');
                exit(json_encode($data,$json_option));
            case 'XML'  :
                // 返回xml格式数据
                header('Content-Type:text/xml; charset=utf-8');
                exit(xml_encode($data));       
            default     :
                header('Content-Type:text/html; charset=utf-8');
                exit($data);   
        }
    }
}